aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app/api/v1/highlights/[highlightId]/route.ts
blob: aa92e7ce02e309b22574ac70888df992521fe78c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { NextRequest } from "next/server";
import { buildHandler } from "@/app/api/v1/utils/handler";

import { zUpdateHighlightSchema } from "@hoarder/shared/types/highlights";

export const dynamic = "force-dynamic";

export const GET = (
  req: NextRequest,
  { params }: { params: { highlightId: string } },
) =>
  buildHandler({
    req,
    handler: async ({ api }) => {
      const highlight = await api.highlights.get({
        highlightId: params.highlightId,
      });
      return { status: 200, resp: highlight };
    },
  });

export const PATCH = (
  req: NextRequest,
  { params }: { params: { highlightId: string } },
) =>
  buildHandler({
    req,
    bodySchema: zUpdateHighlightSchema.omit({ highlightId: true }),
    handler: async ({ api, body }) => {
      const highlight = await api.highlights.update({
        highlightId: params.highlightId,
        ...body!,
      });
      return { status: 200, resp: highlight };
    },
  });

export const DELETE = (
  req: NextRequest,
  { params }: { params: { highlightId: string } },
) =>
  buildHandler({
    req,
    handler: async ({ api }) => {
      const highlight = await api.highlights.delete({
        highlightId: params.highlightId,
      });
      return { status: 200, resp: highlight };
    },
  });